﻿#pragma once

//朴素版本
#include <iostream>
#include <algorithm>

using namespace std;
const int N = 110;

int v[N], w[N], s[N];
int f[N][N];
int n, m;

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> s[i];

    for (int i = 1; i <= n; i++) {//枚举背包
        for (int j = 1; j <= m; j++) {//枚举体积
            for (int k = 0; k <= s[i]; k++) {
                if (j >= k * v[i]) {
                    f[i][j] = max(f[i][j], f[i - 1][j - k * v[i]] + k * w[i]);
                }
            }
        }
    }

    cout << f[n][m] << endl;

    return 0;
}





//数学证明+滚动数组
时间复杂度O(n∗logs∗v)

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 25000;

int f[N], v[N], w[N];
int n, m;

int main() {
    cin >> n >> m;

    //将每种物品根据物件个数进行打包
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int a, b, s;
        cin >> a >> b >> s;

        int k = 1;
        while (k <= s) {
            cnt++;
            v[cnt] = k * a;
            w[cnt] = k * b;
            s -= k;
            k *= 2;
        }
        if (s > 0) {
            cnt++;
            v[cnt] = s * a;
            w[cnt] = s * b;
        }

    }

    //多重背包转化为01背包问题
    for (int i = 1; i <= cnt; i++) {
        for (int j = m; j >= v[i]; j--) {
            f[j] = max(f[j], f[j - v[i]] + w[i]);
        }
    }

    cout << f[m] << endl;

    return 0;
}
